/*Joseph A. Coll
7/8/2023
Cleaning ANES */

use "anes_timeseries_2020_stata_20220210.dta", clear

*Political Interest to Politics/Elections
tab V201005
tab V201005, nol
recode V201005 (1=4 "High") (2=3 "Moderately High") (3=2 "Moderately Low") (-9 4/5 =1 "Low"), gen(poli_int_politics)
label var poli_int_politics "Political Interest"
tab poli_int_politics

*Ideology
tab V201200
tab V201200, nol
recode V201200 (1=1 "V. Lib.") (2=2 "Lib.") (3=3 "S. Lib.") (-9 -8 4 99= 4 "Moderate") (5=5 "S. Cons.") (6=6 "Cons.") (7=7 "V. Cons."), gen(conservativism)
label var conservativism Conservativism
tab conservativism

recode V201200 (1/3=1 "Liberal") (-9 -8 4 99= 2 "Moderate") (5/7=3 "Conservative"), gen(conservativism3)
label var conservativism3 Conservativism
tab conservativism3

*Age
tab V201507x
sum V201507x if V201507x !=-9
recode V201507x (-9=52), gen(age)
label var age Age
tab age

gen age2 =age *age
label var age2 "Age Squared"
tab age2

*Education
tab V201510
tab V201510, nol
tab V201510 if V201510 <95 & V201510 >0
sum V201510 if V201510 <95 & V201510 >0
recode V201510 (1=1 "<HS") (2=2 "HS Grad.") (3=3 "Some Coll.") (-9 -8 4/5 95=4 "Assoc.") (6=5 "Bach.") (7=6 "MA") (8=7 "Adv."), gen(educ)
label var educ Education
tab educ

*Latino
tab V201546
tab V201546, nol
recode V201546 (1=1 "Latino") (-9 -8 2=0 "Not Latino"), gen(hispanic)
replace hispanic = 1 if V201549x ==3
label var hispanic Hispanic
tab hispanic

*Race
tab V201549x
recode V201549x (1=1 "White") (-9 -8 2/6=0 "Not White"), gen(white_non_hispanic)
label var white_non_hispanic "White"
tab white_non_hispanic

tab V201549x
recode V201549x (2=1 "Black") (-9 -8 1 3/6=0 "Not Black"), gen(black_non_hispanic)
label var black_non_hispanic "Black"
tab black_non_hispanic

tab V201549x
recode V201549x (-9 -8 1 4/6=1 "Other Race") (1 2 3=0 "Not Other Race"), gen(other_non_hispanic)
label var other_non_hispanic "Other Race"
tab other_non_hispanic

*Income
tab V202468x
sum V202468x if V202468x >0
clonevar income_mean = V202468x 
recode income_mean (-9/-1=7)
label var income_mean Income
tab income_mean 

*Party
tab V201231x
recode V201231x (1/2=1 "Democrat") (-9/-8 3/7=0 "Not Democrat"), gen(dem_no_lean)
label var dem_no_lean Democrat
tab dem_no_lean

recode V201231x (1/3=1 "Democrat") (-9 -8 4/7=0 "Not Democrat"), gen(dem_w_lean)
label var dem_w_lean "Democrat"
tab dem_w_lean 

recode V201231x (-9 -8 4=1 "Independent") (1/3 5/7=0 "Not Independent"), gen(ind_nolean)
label var ind_nolean"Independent"
tab ind_nolean

recode V201231x (3/5=1 "Independent") (-9/-8 1/2 6/7=0 "Not Independent"), gen(ind_w_lean)
label var ind_w_lean Independent
tab ind_w_lean

recode V201231x (6/7=1 "Republican") (-9/-8 1/5=0 "Not Republican"), gen(rep_no_lean)
label var rep_no_lean Republican
tab rep_no_lean

recode V201231x (5/7=1 "Republican") (-9 -8 1/4=0 "Not Republican"), gen(rep_w_lean)
label var rep_w_lean "Republican"
tab rep_w_lean 

recode V201231x (1=1 "Strong Dem.") (2=2 "Mod. Dem.") (3=3 "Lean Dem.") (4=4 "Independent") (5=5 "Lean Rep.") (6=6 "Mod. Rep.") (7=7 "Strong Rep.") (-9/-8=.), gen(party_scale)
label var party_scale "Party"
tab party_scale 

*Black Feeling Thermometer
tab V202480
sum V202480 if V202480 >-1
recode V202480 (-9/-4=72), gen (ft_black)
label var ft_black "Black Affect"
tab ft_black 

*Black influence in politics
tab V202495
tab V202495, nol m
recode V202495 (-9/-5=.) (1=3 "B.A. Have too Much Influence") (2=2 "B.A. Have Right Amount of Influence") (3=1 "B.A. Have Too Little Influence"), gen(black_influence)
label var black_influence "Black American Political Influence"
fre black_influence

*White influence in politics
tab V202494
tab V202494, nol m
recode V202494 (-9/-5=.) (1=3 "W.A. Have too Much Influence") (2=2 "W.A. Have Right Amount of Influence") (3=1 "W.A. Have Too Little Influence"), gen(white_influence)
label var white_influence "White American Political Influence"
fre white_influence

*Political influence difference
gen black_white_influence5 = .
replace black_white_influence5 = black_influence - white_influence
label var black_white_influence5 "Black-White Political Influence"
replace black_white_influence5 = black_white_influence5  +3
fre black_white_influence5
label def black_white_influence5 1 "White way too much" 2 "White too much" 3 "Even" 4 "Black too much" 5 "Black way too much", replace
label val black_white_influence5 black_white_influence5 
fre black_white_influence5 

recode black_white_influence5 (1/2=1 "Low Poli. Threat") (3=2 "Moderate Poli. Threat") (4/5=3 "High Poli. Threat"), gen(black_white_influence3)

*Racial resentment
tab V202300 
tab V202300, nol
recode V202300 (1=5 "Agree Strongly") (2=4 "Agree Somewhat") (3=3 "Neither") (4=2 "Disagree Somehwat") (5=1 "Disagree Strongly") (-9/-1=.), gen(racism_nofavors)
label var racism_nofavors "Blacks Should Work w/o Special Favors"
tab racism_nofavors

tab V202301 
tab V202301, nol
recode V202301 (1=1 "Agree Strongly") (2=2 "Agree Somewhat") (3=3 "Neither") (4=4 "Disagree Somehwat") (5=5 "Disagree Strongly") (-9/-1=.), gen(racism_slaverydifficult)
label var racism_slaverydifficult "Slavery/Discrim. Limit Blacks (rev.)"
tab racism_slaverydifficult

tab V202302 
tab V202302, nol
recode  V202302 (1=1 "Agree Strongly") (2=2 "Agree Somewhat") (3=3 "Neither") (4=4 "Disagree Somehwat") (5=5 "Disagree Strongly") (-9/-1=.), gen(racism_dontgetless)
label var racism_dontgetless "Blacks Get Less (rev.)"
tab racism_dontgetless

tab V202303
tab V202303, nol
recode V202303 (1=5 "Agree Strongly") (2=4 "Agree Somewhat") (3=3 "Neither") (4=2 "Disagree Somehwat") (5=1 "Disagree Strongly") (-9/-1=.), gen(racism_blacksshouldtry)
label var racism_blacksshouldtry "Blacks Should Try Harder"
tab racism_blacksshouldtry

gen racism_scale2_1= .
replace racism_scale2_1 = (racism_nofavors + racism_slaverydifficult + racism_dontgetless + racism_blacksshouldtry)-4
label var racism_scale2_1 "Racial Resentment"
tab racism_scale2_1 

*Stereotypes
tab V202516 

	*Hard working
	tab V202515
	tab V202515 if white_non ==1 
	recode V202515 (1=1 "Hard-working") (2=2) (3=3) (4=4 ) (5=5) (6=6) (7=7 "Lazy") (-9/-1=.), gen(stereo_white_lazy)
	label var stereo_white_lazy "White Lazy" 
	tab stereo_white_lazy

	tab V202516
	tab V202516 if white_non ==1 
	recode V202516 (1=1 "Hard-working") (2=2) (3=3) (4=4 ) (5=5) (6=6) (7=7 "Lazy") (-9/-1=.), gen(stereo_black_lazy)
	label var stereo_black_lazy "Black Lazy" 
	tab stereo_black_lazy

	*Differences 
	gen stereo_lazy_black_diff = .
	replace stereo_lazy_black_diff  = stereo_white_lazy - stereo_black_lazy if white_non ==1
	tab stereo_lazy_black_diff
	recode stereo_lazy_black_diff (-6/-1=1 "Black Lazier") (0=0 "Same") (1/6=-1 "White Lazier"), gen(stereo_lazy_black_diff3)
	label var stereo_lazy_black_diff3 "Black Lazier"
	tab stereo_lazy_black_diff3

	*Violent
	tab V202521
	tab V202521 if white_non ==1 
	recode V202521 (1=1 "Peaceful") (2=2) (3=3) (4=4 ) (5=5) (6=6) (7=7 "Violent") (-9/-1=.), gen(stereo_white_violent)
	label var stereo_white_violent "White Violent" 
	tab stereo_white_violent

	recode V202521 (1/3=-1 "Peaceful") (4=0 "Neither") (5/7=1 "Violent") (-9/-1=.), gen(stereo_white_violent3)
	label var stereo_white_violent3 "White Violent" 
	tab stereo_white_violent3

	tab V202522
	tab V202522 if white_non ==1 
	recode V202522 (1=1 "Peaceful") (2=2) (3=3) (4=4 ) (5=5) (6=6) (7=7 "Violent") (-9/-1=.), gen(stereo_black_violent)
	label var stereo_black_violent "Symbolic Threat" 
	tab stereo_black_violent

	recode V202522 (1/3=-1 "Peaceful") (4=0 "Neither") (5/7=1 "Violent") (-9/-1=.), gen(stereo_black_violent3)
	label var stereo_black_violent3 "Symbolic Threat" 
	tab stereo_black_violent3

	*Differences 
	gen stereo_violent_black_diff = .
	replace stereo_violent_black_diff  = stereo_black_violent -  stereo_white_violent if white_non ==1
	label var stereo_violent_black_diff "Symbolic Threat"	
	tab stereo_violent_black_diff
	clonevar stereo_violent_black_diff_orig = stereo_violent_black_diff
	recode stereo_violent_black_diff (-6/-1=1 "White More Violent") (0=2 "Same") (1/6=3 "Black More Violent"), gen(stereo_violent_black_diff3)
	tab stereo_violent_black_diff3
	label var stereo_violent_black_diff3 "Symbolic Threat"	

*Economic threat whites lose jobs to minorities
fre V202487
recode V202487 (1=5 "Extremely likely") (2=4 "Very likely") (3=3 "Moderately likely") (4=2 "Slightly likely") (5=1 "Not at all likely") (-9/-1=.), gen(whites_lose_jobs5)
label var whites_lose_jobs5 "Economic Threat"
fre whites_lose_jobs5

recode V202487 (1/3=3 "Highly likely") (4=2 "Moderately likely") (5=1 "Not at all likely") (-9/-1=.), gen(whites_lose_jobs3)
label var whites_lose_jobs3 "Economic Threat"
fre whites_lose_jobs3

*Immigrants commit crimes
fre V202239x
clonevar ii_crime = V202239x
recode ii_crime (-7/-1=.) (5/7=4)
revrs ii_crime 
fre revii_crime 
label var revii_crime  "Illegal Immig. Increases Crime"
drop ii_crime 
rename revii_crime ii_crime 
fre ii_crime

*Support for Felon Disenfranchisment
tab V201360 
tab V201360, nol
recode V201360 (1=1 "Opposes FD") (2=3 "Supports FD") (-9 -8 3=2 "Neither"), gen(supports_fd)
label var supports_fd "Supports Felon Disenf."
tab supports_fd

revrs supports_fd
fre revsupports_fd

tab V201362x
tab V201362x, nol
recode V201362x (1=1 "Opposes Greatly") (2=2 "Opposes Moderately") (3=3 "Opposes a Little") (-2 4=4 "Neither") (5=5 "Favors a Little") (6=6 "Favors Moderately") (7=7 "Favors Greatly"), gen(supports_fd_scale)
label var supports_fd_scale "Felon Disenf. Support Scale"
tab supports_fd_scale

*White Racial Importance
tab V202499x
tab V202499x, nol
tab V202499x if white_non == 1
recode V202499x (1=5 "Extremely Important") (2=4 "Very Important") (3=3 "Moderately Important") (4=2 "A Little Important") (5=1 "Not at all Important") (-9/-1=.), gen(racial_importance)
label var racial_importance "Racial Importance"
tab racial_importance

*Spending on Crime
tab V201311x 
tab V201311x, nol
recode V201311x (1=5 "Increase a Lot") (2=4 "Increase a Little") (3=3 "Kept the Same") (4=2 "Decreased a Little") (5=1 "Decreased a Lot") (-2 . =3), gen(spending_crime)
label var spending_crime "+Crime Spending"

*State
tab V203001
tab V203001, nol
statastates, abbreviation(V203001)
replace state_name = proper(state_name)
rename V203001 state_abbrev
gen year = 2020

merge m:m state_abbrev year using "Percent Black by State.dta", gen(_mergePercBlack)
bro if _mergePercBlack !=3

gen fd_policy = .		
replace fd_policy = 1 if state_name == "District of Columbia"
replace fd_policy = 1 if state_name == "Maine"
replace fd_policy = 1 if state_name == "Vermont"
replace fd_policy= 2 if state_name == "California"
replace fd_policy= 2 if state_name == "Colorado"
replace fd_policy= 2 if state_name == "Connecticut"
replace fd_policy= 2 if state_name == "Hawaii"
replace fd_policy= 2 if state_name == "Illinois"
replace fd_policy= 2 if state_name == "Indiana"
replace fd_policy= 2 if state_name == "Maryland"
replace fd_policy= 2 if state_name == "Massachusetts"
replace fd_policy= 2 if state_name == "Michigan"
replace fd_policy= 2 if state_name == "Minnesota"
replace fd_policy= 2 if state_name == "Montana"
replace fd_policy= 2 if state_name == "Nevada"
replace fd_policy= 2 if state_name == "New Hampshire"
replace fd_policy= 2 if state_name == "New Jersey"
replace fd_policy= 2 if state_name == "New York"
replace fd_policy= 2 if state_name == "New Mexico"
replace fd_policy= 2 if state_name == "North Dakota"
replace fd_policy= 2 if state_name == "Ohio"
replace fd_policy= 2 if state_name == "Oregon"
replace fd_policy= 2 if state_name == "Pennsylvania"
replace fd_policy= 2 if state_name == "Rhode Island"
replace fd_policy= 2 if state_name == "Utah"
replace fd_policy= 2 if state_name == "Washington"
replace fd_policy= 3 if state_name == "Alaska"
replace fd_policy= 3 if state_name == "Arkansas"
replace fd_policy= 3 if state_name == "Georgia"
replace fd_policy= 3 if state_name == "Idaho"
replace fd_policy= 3 if state_name == "Kansas"
replace fd_policy= 3 if state_name == "Louisiana"
replace fd_policy= 3 if state_name == "Missouri"
replace fd_policy= 3 if state_name == "Nebraska"
replace fd_policy= 3 if state_name == "North Carolina"
replace fd_policy= 3 if state_name == "Oklahoma"
replace fd_policy= 3 if state_name == "South Carolina"
replace fd_policy= 3 if state_name == "South Dakota"
replace fd_policy= 3 if state_name == "Texas"
replace fd_policy= 3 if state_name == "West Virginia"
replace fd_policy= 3 if state_name == "Wisconsin"
replace fd_policy= 4 if state_name == "Alabama"
replace fd_policy= 4 if state_name == "Arizona"
replace fd_policy= 4 if state_name == "Delaware"
replace fd_policy= 4 if state_name == "Florida"
replace fd_policy= 4 if state_name == "Iowa"
replace fd_policy= 4 if state_name == "Kentucky"
replace fd_policy= 4 if state_name == "Mississippi"
replace fd_policy= 4 if state_name == "Tennessee"
replace fd_policy= 4 if state_name == "Virginia"
replace fd_policy= 4 if state_name == "Wyoming"
label def fd_policy 1 "No Disenfranchisement" 2 "During Incarceration" 3 "Until Sentence Completion" 4 "Post-Sentence Waiting Period/Additional Action"
label val fd_policy fd_policy
label var fd_policy "FD Policy"

merge m:m state_name year using "Legislative Diversity Data Cleaned and Collapsed.dta", gen(_mergeSLD)
drop _mergeSLD

clonevar post_weight = V200010b
clonevar pre_weight = V200010a

*Drop non-white respondents or those who did not answer main IV questions
drop if white_non_hispanic !=1
drop if black_influence == .

*Mode
fre V200002 
recode V200002 (3=1 "Self-Administered") (1/2=0 "Not Self-Administered"), gen(survey_mode)
label def survey_mode 1 "SA" 0 "Non-SA", replace
label val survey_mode survey_mode 
label var survey_mode "Survey Mode"
fre survey_mode 

save "Political Racial Threat White Disenfranchisement Support 2020 Data Cleaned.dta", replace